﻿///////////////////////////////////////////////////////////////////////////////////////////////
// System.Text.Parsing - © 2011 Sebastien Pellizzari
// Released under the MIT License (http://www.opensource.org/licenses/mit-license.php)
///////////////////////////////////////////////////////////////////////////////////////////////

namespace System.Text.Parsing
{
    /// <summary>Represents the definition of a code block in a grammar.</summary>
    public sealed class GrammarCodeBlock
    {
        private readonly GrammarTextValue _name;            // The name of the code block.
        private readonly GrammarTextValue _code;            // The code of the code block.
        private readonly GrammarSourceRange _sourceInfo;    // Source info.

        //-----------------------------------------------------------------------
        //     Properties
        //-----------------------------------------------------------------------

        /// <summary>Gets the name of the code block.</summary>
        public GrammarTextValue Name { get { return _name; } }
        /// <summary>Gets the code of the code block.</summary>
        public GrammarTextValue Code { get { return _code; } }
        /// <summary>Gets the code block source information.</summary>
        public GrammarSourceRange SourceInfo { get { return _sourceInfo; } }

        //-----------------------------------------------------------------------
        //     Constructors
        //-----------------------------------------------------------------------

        /// <summary>Initializes an instance of the <see cref="GrammarCodeBlock"/> class.</summary>
        /// <param name="name">The name of the code block.</param>
        /// <param name="code">The code of the code block.</param>
        /// <param name="sourceInfo">Source information for the code block.</param>
        public GrammarCodeBlock(GrammarTextValue name, GrammarTextValue code, GrammarSourceRange sourceInfo)
        {
            if (name.Text == null) throw new ArgumentNullException("name.Text");
            if (code.Text == null) throw new ArgumentNullException("code.Text");
            _name = name;
            _code = code;
            _sourceInfo = sourceInfo;
        }
    }
}
